<?php

namespace app\index\controller;

use think\exception\ValidateException;
use app\model\Incomelog;
use app\model\Member;

class IncomelogController extends Base
{
    /**
     * 获取团队收入记录列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $uid = UID();
        $ptype = input('get.ptype', '', 'serach_in');
        $page = input('get.page', 1, 'intval');
        $limit = input('get.limit', 20, 'intval');
        $where['weid'] = weid();
        $where['uid'] = $uid;
        $where['ptype'] = $ptype;
        $data = Incomelog::where($where)
            ->order('id desc')
            ->limit($limit * ($page - 1), $limit)
            ->select()
            ->toArray();
        $count = Incomelog::where($where)->count();

        foreach ($data as &$vo) {
            $vo['username'] = Member::get_name($vo['buyer_id']);
            $vo['pay_time'] = time_format($vo['pay_time']);
        }
        return $this->json(['code'=>1000, 'msg' => 'success', 'data'=>['item'=>$data, 'count'=>$count]]);
    }


}
